//
//  MineOrderTableViewCell.m
//  WuJieLive
//
//  Created by 张瀚坤 on 2017/10/25.
//  Copyright © 2017年 zhk. All rights reserved.
//

#import "MineOrderTableViewCell.h"

#define BtnWidth 50
#define BtnHeight 50

@implementation MineOrderTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupView];
    }
    return self;
}

- (void)setupView
{
    self.orderLabel = [[UILabel alloc]init];
    self.orderLabel.text = @"我的订单";
    self.orderLabel.textColor = Color(51, 51, 51);
    self.orderLabel.font = FontSize(14);
    [self.contentView addSubview:self.orderLabel];
    [self.orderLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.top.offset(17);
    }];
    
    self.rightImage = [[UIImageView alloc]init];
    self.rightImage.image = Image(@"icon_close");
    [self.contentView addSubview:self.rightImage];
    [self.rightImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-20);
        make.centerY.equalTo(self.orderLabel);
        make.size.mas_offset(CGSizeMake(10, 13));
    }];
    
    self.allLabel = [[UILabel alloc]init];
    [self.contentView addSubview:self.allLabel];
    self.allLabel.textColor =Color(153, 153, 153);
    self.allLabel.text = @"查看全部订单";
    self.allLabel.font = FontSize(14);
    [self.allLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.rightImage.mas_left).offset(-10);
        make.centerY.equalTo(self.rightImage);
    }];
    
    self.lineView = [[UIView alloc]init];
    [self.contentView addSubview:self.lineView];
    self.lineView.backgroundColor = TextLessImportColor;
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.contentView);
        make.top.equalTo(self.orderLabel.mas_bottom).offset(17);
        make.height.offset(1);
    }];
    
    self.array = [NSMutableArray array];
    
    for (int i = 0; i < 5; i ++) {
        self.btn = [[HKButton alloc]init];
        [self.contentView addSubview:self.btn];
        self.btn.tag = 1000 + i;
        [self.btn setTitle:self.titleArray[i] forState:(UIControlStateNormal)];
        [self.btn setTitleColor:TextLessImportColor forState:(UIControlStateNormal)];
        [self.btn setImage:Image(self.imageArray[i]) forState:(UIControlStateNormal)];
        CGFloat temp = kScreenWidth - BtnWidth * 5;
        CGFloat space = temp / 6;
        [self.btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.lineView.mas_bottom).offset(15);
            make.left.offset(space * (i + 1) + i * BtnWidth);
            make.size.mas_offset(CGSizeMake(BtnWidth, BtnHeight));
        }];
        [self.btn addTarget:self action:@selector(orderBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
        [self.array addObject:self.btn];
    }
}

- (void)orderBtnAction:(UIButton *)sender
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(orderBtnAction:)]) {
        [self.delegate orderBtnAction:sender.tag];
    }
}

-(NSArray *)imageArray
{
    if (!_imageArray) {
        _imageArray = @[@"icon_user_待付款",@"icon_user_待发货",@"icon_user_待收货",@"icon_user_待评价",@"icon_user_售后"];
    }
    return _imageArray;
}

- (NSArray *)titleArray
{
    if (!_titleArray) {
        _titleArray = @[@"待付款",@"待发货",@"待收货",@"待评价",@"售后"];
    }
    return _titleArray;
}

- (void)setbadge:(NSString *)badge withTag:(NSInteger)tag
{
    for (int i = 0; i < self.array.count; i ++) {
        HKButton * btn = self.array[i];
        if (tag == btn.tag) {
            btn.badgeValue = badge;
            [btn layoutSubviews];
        }
    }
}

@end
